/****************************************************
 * Description: DAOimpl for 用户组角色
 * Copyright:   Copyright (c) 2013
 * Company:     beiwaionline
 * @author      bfsu
 * @version     1.0
 * @see
	HISTORY
    *  2013-08-08 bfsu Create File
**************************************************/

package com.bfsuolframework.security.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bfsuolframework.security.dao.GroupRoleDAO;
import com.bfsuolframework.security.entity.GroupRole;
import com.bfsuolframework.core.dao.HibernateDAOSupport;
import com.bfsuolframework.core.dao.support.HqlParameter;

@Repository
public class GroupRoleDAOImpl extends HibernateDAOSupport<GroupRole> implements GroupRoleDAO {

    //通过 用户组主键 查询 用户组角色 集合
    private final String FIND_GROUPROLE_BYGROUPID = "FROM GroupRole groupRole WHERE groupRole.group.id = :groupId";
	
    //通过 角色主键 查询 用户组角色 集合
    private final String FIND_GROUPROLE_BYROLEID = "FROM GroupRole groupRole WHERE groupRole.role.id = :roleId";
	
	
    /**
     * 通过 用户组主键 查询 用户组角色
     * @return 用户组角色 集合
     */
    public List<GroupRole> findGroupRolesByGroupId(Long groupId){
        return findAll(FIND_GROUPROLE_BYGROUPID, HqlParameter.newInstance("groupId", groupId));
    }
	
    /**
     * 通过 角色主键 查询 用户组角色
     * @return 用户组角色 集合
     */
    public List<GroupRole> findGroupRolesByRoleId(Long roleId){
        return findAll(FIND_GROUPROLE_BYROLEID, HqlParameter.newInstance("roleId", roleId));
    }

	/* (non-Javadoc)
	 * @see GroupRoleDAO#deleteByGroupId(java.lang.Long)
	 */
	public void deleteByGroupId(Long groupId) {
		
		this.executeHql("delete from GroupRole  where group.id = :groupId",HqlParameter.newInstance("groupId",groupId));
	}
	

}